package xdu.lz.stage5_jucUtils.chapter2_cycliBarrier;

import java.util.concurrent.BrokenBarrierException;
import java.util.concurrent.CyclicBarrier;

/**
 * Created at 2019/10/18 0018 下午 5:19
 */
public class CB_test2_broken {

    public static void main(String[] args) throws BrokenBarrierException, InterruptedException {
        CyclicBarrier cyclicBarrier = new CyclicBarrier(2,()->{
            System.out.println("done");
        });

        new Thread(() -> {
            try {
                Thread.sleep(3000);
                cyclicBarrier.await();
            } catch (Exception e) {
                e.printStackTrace();

            }
        }).start();



        new Thread(()->{
            try {
                cyclicBarrier.await();
            } catch (Exception e) {
                System.out.println("收到reset指令:"+e.getMessage());
            }
        }).start();

        Thread.sleep(100);
        cyclicBarrier.reset();

        Thread.sleep(3000);
        //因为被重置了为2了，所以这里要是不await那么就只有t1await，程序会被t1阻塞住
        cyclicBarrier.await();

    }
}
